﻿namespace TableCore.Core
{
    public abstract class Disposable : System.IDisposable
    {
        protected readonly object _lock = new object();
        bool mDisposed;
        public bool IsValid { get { lock (_lock) { return !mDisposed; } } }

        public void Dispose()
        {
            lock (_lock)
            {
                if (mDisposed)
                    return;
                mDisposed = true;
            }
            OnDisposing();
        }

        ~Disposable() { Dispose(); }

        protected abstract void OnDisposing();
    }
}
